package dev.alm.reggietakeoutservice.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

// MD5工具类
public class Md5Util {

    // 加密
    public static String encrypt(String input) throws NoSuchAlgorithmException {
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        byte[] bytes = input.getBytes();
        byte[] digest = md5.digest(bytes);
        StringBuffer sb = new StringBuffer();
        for (byte b : digest) {
            sb.append(String.format("%02x", b & 0xff));
        }
        return sb.toString();
    }

    // 解密
    public static Boolean decrypt(String input, String encrypted) throws NoSuchAlgorithmException {
        return encrypt(input).equals(encrypted);
    }

}
